package com.yanshaohui.springboot.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

import com.yanshaohui.springboot.entity.AddressEntity;

@Mapper
public interface AddressMapper {

	@Select("SELECT * FROM ADDRESS WHERE name = #{name}")
	AddressEntity findByName(@Param("name") String name);
	
	@Select("SELECT address FROM ADDRESS WHERE name = #{name}")
	String findAddressByName(@Param("name") String name);

	@Insert("INSERT INTO ADDRESS(name, address, post ,tel) VALUES(#{name}, #{address}, #{post}, #{tel})")
	@Options(useGeneratedKeys = true, keyProperty = "id") 
	int insert(AddressEntity address);
	
	@Insert("INSERT INTO ADDRESS(name, address, post ,tel) VALUES(#{name}, #{address}, #{post}, #{tel})")
	@Options(useGeneratedKeys = true, keyProperty = "id") 
	int insert2(@Param("name") String name, @Param("address") String address, @Param("post") String post ,@Param("tel") String tel);
	
	@Insert("INSERT INTO ADDRESS(name, address, post ,tel) VALUES(#{name}, #{address}, #{post}, #{tel})")
	@Options(useGeneratedKeys = true, keyProperty = "id") 
	int insert3(Map<String, Object> map);

	@Update("UPDATE ADDRESS SET name=#{name},address=#{address},post=#{post},tel=#{tel} WHERE id=#{id}")
	void update(AddressEntity address);

	@Delete("DELETE FROM ADDRESS WHERE id =#{id}")
	void delete(Long id);
	
	/////////////////////////以下为动态sql
	@SelectProvider(type = AddressDynaSqlProvider.class,method = "selectAddress") 
	List<AddressEntity> dynaFindByName(AddressEntity entity);

	@InsertProvider(type = AddressDynaSqlProvider.class,method = "insertAddress") 
	int dynaInsert(AddressEntity entity);
	
	@UpdateProvider(type = AddressDynaSqlProvider.class,method = "updateAddress") 
	void dynaUpdate(AddressEntity entity);
	
	
	// @Select("SELECT * FROM user WHERE name = #{name}")
	// User findByName(@Param("name") String name);
	//
	// @Results({
	// @Result(property = "name", column = "name"),
	// @Result(property = "age", column = "age")
	// })
	// @Select("SELECT name, age FROM user")
	// List<User> findAll();
	//
	// @Insert("INSERT INTO user(name, age) VALUES(#{name}, #{age})")
	// int insert(@Param("name") String name, @Param("age") Integer age);
	//
	// @Update("UPDATE user SET age=#{age} WHERE name=#{name}")
	// void update(User user);
	//
	// @Delete("DELETE FROM user WHERE id =#{id}")
	// void delete(Long id);
	//
	// @Insert("INSERT INTO user(name, age) VALUES(#{name}, #{age})")
	// int insertByUser(User user);
	//
	// @Insert("INSERT INTO user(name, age) VALUES(#{name,jdbcType=VARCHAR},
	// #{age,jdbcType=INTEGER})")
	// int insertByMap(Map<String, Object> map);

}